<?php
# !!!!!!!!!! DON'T MAKE ANY CHANGE IF YOU DON'T KNOW WHAT YOU'RE DOING !!!!!!!!!!
// --------------------------------------------------------------------------------------------------------------
// File Name              :	item.php
// Last Modification Time	:	2008-02-01 24:00
// Last Modified by       :	turker (turker.biz@gmail.com)
// list of modifications  :
//
//	- 2008-02-01 turker
//		* 24:00 file created.
//
// --------------------------------------------------------------------------------------------------------------
if (eregi("item.php",$_SERVER['PHP_SELF'])) {
	header ("Location:../index.php");
	exit;
}

$id=getID($ITEMS_TABLE);
if (!$id) {
  header ("Location:$SITE_URL/index.php?page=404");
	exit;
}

?>
<!--div:icerik -->
    <div id="icerik">
<?php
# urun kategorisini bul
$referer=@parse_url($_SERVER['HTTP_REFERER']);
$path=@$referer['path'];
$query=@$referer['query'];
$cat_id=0;
if (eregi('category',$query)&&eregi($SITE_URL,$referer)) { # onceki sayfaya gore bul
  preg_match('@^page=[a-z]+&id=([0-9]+)[&p=[0-9]+]?$@i',$query,$sub);
  $cat_id=$sub[1];
}
elseif (eregi('category',$path)&&eregi($SITE_URL,$referer)) {
  preg_match('@/category/(.*)/?$@i',$path,$sub);
  $cat_id=getCatID($sub[1]);
}
else { # sayfa direk acilmis
  $q=$mysql->query("select cat_id from $ITEM_CATS_TABLE where item_id='$id' and `primary`='1'");
  $cat_id=$mysql->result($q,'cat_id');
}
echo '<p>'.listCatParents($cat_id).'</p>';
# /urun kategorisini bul

$hook->itemAdmin();
$item=getItemAll($id);
/*
$item['item'] ürün bilgileri
id, item, summary, info, name, home, new, lang, show_price, xml_code, image, date, brand_id, active, order

$item['prices'] ürün fiyatları
id, item_id, exchange_id, price, info, campaign, campaign_price, active, vat, ename, exchange

$item['images'] ürün fotoları
id, item_id, image, active, date
*/

# ürün detaları
$title=$prep->html($item['item']['item']); # urun adı*
$summary=$prep->html($item['item']['summary']); # urun özeti*
$description=nl2br($item['item']['info']); # urun açıklaması*
$new=$item['item']['new']; # yeni urun*
$image=$item['item']['image']; # urun mini foto*
$show_price=$item['item']['show_price']; # fiyat goster*

if (empty($image)||!file_exists('img/mid/'.$image))
  $image='<img src="template/img/noimg.png" align="left" class="item-img" title="'.$title.'" />';
else {
  $image='<a rel="shadowbox" href="img/big/'.$image.'" title="'.$_LANG['item']['itemphoto'].'">'
        .'<img src="img/mid/'.$image.'" align="left" class="item-img imglist" title="'.$title.'" /></a>';
  $array=array('id'=>$id,'image'=>$item['item']['image']);
  if (@is_array($item['images'])) array_unshift($item['images'],$array);
  else $item['images'][]=$array;
}

if ($new) $new='<img src="template/img/yeni.gif" />'; else $new='';
$campaign='';

if (empty($description)) $description=$_LANG['item']['nodesc'];
# /ürün detaları

# ürün fiyatları
$priceList='<table width="100%" cellpadding="2" cellspacing="0" id="pricelist"><tbody>';
if (@$item['prices']) {
  $count=count($item['prices']);
  for ($i=0;$i<$count;$i++) {
    $price_id=$item['prices'][$i]['id']; #*
    $ename=$item['prices'][$i]['ename']; # kur adı*
    $exchange=$item['prices'][$i]['exchange']; # kur
    $price=$item['prices'][$i]['price']; # fiyat*
    $info=$prep->html($item['prices'][$i]['info']); # fiyat açıklaması*
    $campaign=$item['prices'][$i]['campaign']; # kampanya*
    $campaign_price=$item['prices'][$i]['campaign_price']; # kampanya fiyatı*
    $vat=$item['prices'][$i]['vat']; # kdv oranı*
    $p_active=$item['prices'][$i]['active'];

    $price="$price $ename +KDV";
    if ($campaign_price>0&&$campaign) {
      $campaign='<img src="template/img/kampanya.gif" align="left" />';
      $price="<s>$price</s> yerine $campaign_price $ename +KDV";
    }
    else $campaign='';

    $active='';
    if (isAdmin()&&$p_active=='1') $active='<img src="template/img/active.gif" title="Fiyat Aktif" />';
    if (isAdmin()&&$p_active=='0') $active='<img src="template/img/notactive.gif" title="Fiyat Aktif Değil" />';
    if (isAdmin()) $show_price=1;

    $basket_link='index.php?page=basket&id='.$id.'&pid='.$price_id;
    $class='';
    if ($i%2!=0) $class='class="gri"';

    if ($show_price) {
      if ($p_active=='1'||(isAdmin()&&$p_active=='0')) {
        $priceList.="<tr id=\"price_$price_id\" $class>";
        if (isAdmin()) {
          $priceList.='<td><img src="template/img/delete.gif" title="Fiyatı Sil" onclick="removePrice(\''.$price_id.'\');" class="imglist" />';
          $priceList.='&nbsp;<img src="template/img/edit.gif" title="Fiyatı Düzenle" onclick="editPrice(\''.$price_id.'\');" class="imglist" />'.$active.'</td>';
        }
        $priceList.="<td height=\"30px\">$info</td><td>$campaign $price</td><td>";
        if ($p_active=='1') $priceList.="<a rel=\"shadowbox;width=760;height=555\" title=\"".$_LANG['item']['basket']."\" href=\"$basket_link\">".$_LANG['item']['addbasket']."</a>";
        $priceList.="</td></tr>";
      } // if
    } // if
  } // for
} // if
$priceList.='</tbody></table>';
# /ürün fiyatları

# ürün fotoları
$imageList='<td>'.$_LANG['item']['nophoto'].'</td>';
//  $image='<a rel="shadowbox" href="img/big/'.$image.'" title="Ürün Fotoğrafı">'
        //.'<img src="img/mid/'.$image.'" align="left" class="item-img imglist" title="'.$title.'" /></a>';
if (@$item['images']) {
  $count=count($item['images']);
  $imageList='';
  for ($i=0;$i<$count;$i++) {
    $img_id=$item['images'][$i]['id'];
    $img=$item['images'][$i]['image'];
    $imageList.='<td align="center"><a rel="shadowbox" href="img/big/'.$img.'" title="'.$_LANG['item']['itemphoto'].'">'
               .'<img src="img/mid/'.$img.'" class="imglist" id="img_'.$img_id.'" /></a>';
    if (isAdmin()) $imageList.='<br /><a href="javascript:void(0);" title="Fotoğrafı Sil" name="img_del" id="'.$img_id.'" />Fotoğrafı Sil</a>';
    $imageList.='</td>';
    if ($i%3==0&&$i!=0) $imageList.='</tr><tr>';
  }
}

$out=<<<html
  <table cellpadding="5" cellspacing="5" width="100%" class="itemtable">
    <tr>
      <td id="item-$id" align="left">
        $new $title<br />$image $summary<br />
      </td>
    </tr>
html;

//id, item_id, exchange_id, price, info, campaign, campaign_price, active, vat, t_price, date
// id, item_id, image, active, date
if (isAdmin()) {
  $exchanges=listexchanges();
  $title=$prep->html($item['item']['item']);
  $info=$prep->html($item['item']['info']);
  $summary=$prep->html($item['item']['summary']);
  $xml_code=$prep->html($item['item']['xml_code']);
  $order=$prep->html($item['item']['order']);
  $home=$item['item']['home'];
  $new=$item['item']['new'];
  $lang=$item['item']['lang'];
  $show_price=$item['item']['show_price'];
  $image=$item['item']['image'];
  $active=$item['item']['active'];
  $brand_id=$item['item']['brand_id'];
  $main_image=$item['item']['image'];

  $dil=listLangs($lang);
  $brands=listBrands($brand_id);
  if ($home=='1') $home=' checked'; else $home='';
  if ($new=='1') $new=' checked'; else $new='';
  if ($show_price=='1') $show_price=' checked'; else $show_price='';
  if ($active=='1') $active=' checked'; else $active='';

  $cats=0;
  $cat_ids=array();
  $extra_cats='Bu ürüne ek kategori tanımlanmamış';
  $q=$mysql->query("select * from $ITEM_CATS_TABLE where item_id='$id' and `primary`='0'");
  if ($mysql->numRows($q)>0) { while ($read=$mysql->fetch($q)) $cat_ids[]="id='".$read['cat_id']."'"; }

  if (count($cat_ids)>0) {
    $extra_cats='';
    $cats=implode(',',$cat_ids);
    $cat_ids=implode(' or ',$cat_ids);
    $q=$mysql->query("select id,title from $CATEGORIES_TABLE where ($cat_ids) order by title asc");
    while ($read=$mysql->fetch($q)) {
      $extra_cats.=' '.$prep->html($read['title']);
      $_SESSION['makeselection'][$read['id']]=$read['title'];
    }
  }

  $out.=<<<html
  <tr>
    <td>
      <a href="javascript:void(0);" title="Ürünü Düzenle" id="itemedit" />Ürünü Düzenle</a> |&nbsp;
      <a href="javascript:void(0);" title="Ürünü Sil" id="itemdel" name="$id" />Ürünü Sil</a> |&nbsp;
      <a href="javascript:void(0);" title="Ürüne Fiyat Ekle" id="priceadd" />Ürüne Fiyat Ekle</a> |&nbsp;
      <a href="javascript:void(0);" title="Ürüne Fotoğraf Ekle" id="photoadd" />Ürüne Fotoğraf Ekle</a>
html;
  $hook->itemAdminLink();
  $out.=<<<html
    </td>
  </tr>
  <tr>
    <td>
    <div id="ajaxloding" style="display:none;"><img src="template/img/loading.gif" title="Yükeniyor..." /></div>
    <div style="display:none;" id="edit">
      <form method="post" id="itemeditForm" class="box" onsubmit="return editItem();">
      <input type="hidden" name="id" value="$id" />
      <input type="hidden" name="main_image" value="$main_image" />
      <label>Başlık:</label> <input type="text" maxlength="100" name="title" id="title" class="input-text" value="$title" /><br />
      <label>Açıklama:</label> <input type="text" maxlength="255" name="info" id="info" class="input-text" value="$summary" /><br />
      <label>İçerik:</label> <textarea name="content" id="content" rows="8" class="textarea">$info</textarea><br />
      <label>Sıra:</label> <input type="text" maxlength="5" name="order" id="order" class="input-mini" value="$order" />&nbsp;&nbsp;
      Aktif: <input type="checkbox" name="active" id="active" value="1" class="checkbox" $active />&nbsp;&nbsp;
      Yeni: <input type="checkbox" name="new" id="new" value="1" class="checkbox" $new />&nbsp;&nbsp;
      Fiyat Göster: <input type="checkbox" name="show_price" id="show_price" value="1" class="checkbox" $show_price />&nbsp;&nbsp;
      Ana Sayfa: <input type="checkbox" name="home" id="home" value="1" class="checkbox" $home /><br />
      <label>Marka:</label> $brands &nbsp;&nbsp; Dil: $dil<br />
      <label>Ürün Kodu:</label> <input type="text" maxlength="45" name="xml_code" id="xml_code"  value="$xml_code" /><br />
      <label>Ürün Foto:</label> <input type="checkbox" name="photo" id="photo" value="1" class="checkbox" /> Ana fotoğrafı sil<br /><br />
      <label>Ek Kategoriler:</label> <span id="listcats">$extra_cats</span><input type="hidden" name="cats" id="cats" value="$cats" />
      <a href="javascript:void(0);" name="catselect" id="catselect" onclick="catSelect(0);">Kategori Seç</a><br /><br />
      <label></label><input type="submit" value=" Ürünü Düzenle " id="save" class="input-submit" />
      </form>
      <hr />
    </div>
    <div style="display:none;" id="itempriceadd">
      <form method="post" onsubmit="return addPrice('$id');" action="" id="priceForm" class="box"/>
      <input type="hidden" name="what" id="what" value="add" />
      <input type="hidden" name="price_id" id="price_id" value="0" />
      <label>Kur:</label> $exchanges<br />
      <label>Fiyat:</label> <input type="text" name="price" id="price" maxlength="10" /><br />
      <label>Açıklama:</label> <input type="text" name="info" id="pinfo" maxlength="255" /><br />
      <label>Kapmanya Fiyatı:</label> <input type="checkbox" class="checkbox" name="campaign" id="campaign" />
      <input type="text" name="campaign_price" id="campaign_price" maxlength="10" /><br />
      <label>KDV:</label> <input type="text" maxlength="5" name="vat" id="vat" class="input-mini" value="18" />&nbsp;&nbsp;
      Aktif: <input type="checkbox" name="active" class="checkbox" id="pactive" value="1" class="checkbox" /><br />
      <label>Fiyat Kodu:</label> <input type="text" name="xml_code" id="pxml_code" maxlength="255" /><br />
      <label></label><input type="submit" value=" Fiyatı Ekle " id="pricebutton" class="input-submit" />
      </form>
      <hr />
    </div>
    <div style="display:none;" id="itemphotoadd">
      <form method="post" id="photoForm" class="box" action="index.php?page=add" enctype="multipart/form-data" />
      <input type="hidden" name="MAX_FILE_SIZE" value="256000" />
      <input type="hidden" name="what" value="itemphotoadd" />
      <input type="hidden" name="item_id" value="$id" />
      Ürün Fotoğrafı: <input name="itemphoto" id="itemphoto" name="itemphoto" type="file" />&nbsp;<br />
      <input type="submit" value=" Fotoğrafı Ekle " class="input-submit" />
      </form>
      <hr />
    </div>
    </td>
  </tr>
html;
}

$hook->item();

if ($SHOW_ITEM_PRICE==0&&!isLogged()) $priceList='';
$itemdesc=$_LANG['item']['itemdesc'];
$itemphotos=$_LANG['item']['itemphotos'];
$out.=<<<html
  <tr>
    <td>$priceList</td>
  </tr>
  <tr>
    <td>
      <div class="tabber">
        <div class="tabbertab">
          <h4>$itemdesc</h4>
          <p>$description</p>
        </div>

        <div class="tabbertab">
          <h4>$itemphotos</h4>
          <p><table width="100%" cellpadding="2" cellspacing="0"><tr>$imageList</tr></table></p>
        </div>

      </div>
    </td>
  </tr>
</table>
<a rel="shadowbox;width=760;height=555" title="fix" href=""></a>
html;

echo $out;
if (goBack()) echo goBack();
?>
    </div>
<!--//div:icerik -->